home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
fileInfoFunctions.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
33KB
|
930 lines
<?php
/**
* Get detailled file information
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.1.1
*/
require_once(INCLUDE_DIR.'mime_type.php');
$_ENV['thumbnailMaxWidth']=(cfRGetVar('tooltipImageWidth'))?cfRGetVar('tooltipImageWidth'):160;
$_ENV['thumbnailMaxHeight']=(cfRGetVar('tooltipImageHeight'))?cfRGetVar('tooltipImageHeight'):120;
/**
* @desc Parse playlist: return a PHP array from a playlist
*
* @param string $completeFilename: path to playlist, or single audio file
* @param boolean $allowedFilesOnly: include only existing and downloadable files
* @param boolean $getProperties: get audio files properties
* @return array(0 => completeFilename, 1 => ...) path and filename of found songs
*/
function fiParsePlaylistFile($completeFilename, $allowedFilesOnly=false, $getProperties=false){
$songs=array();
$path=cfDirName($completeFilename); if(substr($path,-1)!='/') $path.='/';
// Dynamic playlist
if($completeFilename=='*playlist*.m3u'){
if(cfRGetVar('shufflePlaylist')) $playlist=cfRGetVar('playlistShuffled');
else $playlist=cfRGetVar('playlist');
foreach ($playlist as $v) $songs[]['cfn']=$v['completeFileName'];
}
// Read M3U playlist file
else switch (cfFileExtension($completeFilename)){
// M3U
case 'm3u':
// Open playlist
if(!file_exists($completeFilename) || (!$handle = fopen ($completeFilename, "r"))) return array();
while (!feof ($handle)) {
$line=trim(fgets($handle, 4096));
if($line && substr($line,0,1)!='#'){
if(substr($line,1,1)!=':') $line=cfJoinPathFile($path,$line);
if(!$allowedFilesOnly) $songs[]['cfn']=$line;
elseif (file_exists($line) && cfFileRights($line,'download')) $songs[]['cfn']=$line;
}
}
fclose($handle);
break;
// Winamp PLS
case 'pls':
// Open playlist
if(!file_exists($completeFilename) || (!$handle = fopen ($completeFilename, "r"))) return array();
while (!feof ($handle)) {
$line=trim(fgets($handle, 4096));
if(substr($line,0,4)=='File' && strpos($line,'=')){
$line=substr($line,strpos($line,'=')+1);
if(substr($line,1,1)!=':') $line=cfJoinPathFile($path,$line);
if(!$allowedFilesOnly) $songs[]['cfn']=$line;
elseif (file_exists($line) && cfFileRights($line,'download')) $songs[]['cfn']=$line;
}
}
fclose($handle);
break;
default:
require_once('explorerFunctions.php');
if(strpos($completeFilename,'*resSpecific*')!==false && cfRGetVar('extAccessFunction')) {
$extAccessFunction = create_function('$completeFilename', cfRGetVar('extAccessFunction'));
if(!($cfn=$extAccessFunction($completeFilename))) return array();
$songs[]=array('cfn'=>$cfn,'efn'=>$completeFilename);
}
else{
if(efFileType($completeFilename)!='audio' && efFileType($completeFilename)!='video') return array();
if(!$allowedFilesOnly) $songs[]['cfn']=$completeFilename;
elseif (file_exists($completeFilename) && cfFileRights($completeFilename,'download')) $songs[]['cfn']=$completeFilename;
}
}
// Get songs properties for embeded tags
if($getProperties){
require_once('explorerFunctions.php');
foreach ($songs as $k=>$v){
$songs[$k]['ai']=efGetAudioInfo($v['cfn'],true);
}
}
return $songs;
}
/**
* @desc Convert an array generated by fiParsePlaylistFile to a playlist file
*
* @param string $playlist: playlist array: ('cfn'=>completeFilename, 'ai'=>array(audio info, see efGetAudioInfo()))
* @param string $playlistFormat: 'm3u','asx','pls','asx','xml'
* @param array $encodingOptions: reencoding options
* ('outputBitrate' for audio reencoding, 'w','h','q','offset' for video, 'URI' to use URI passed into 'fileLink' key of $v)
* @param string $addressMode: 'relative' | 'absolute'
* @param boolean $preUTF8Encode
* @return unknown
*/
function fiArrayToPlaylist($playlist, $playlistFormat, $encodingOptions, $addressMode="relative", $preUTF8Encode=true){
function fileLink($v, $encodingOptions, $addressMode, $preUTF8Encode){
$cfn=$v['cfn']; $efn=(isset($v['efn']))?$v['efn']:$cfn;
// Passed URI
if($encodingOptions=='URI' && isset($v['uri'])) return $v['uri'];
// Audio files
if(efFileType($cfn)=='audio') return cfExtAudio($efn,((isset($encodingOptions['outputBitrate'])?"audio/".$encodingOptions['outputBitrate']."/":'')),$addressMode,$preUTF8Encode);
// Video files
return cfExtVideo($efn,$encodingOptions,$addressMode,$preUTF8Encode);
}
require_once(INCLUDE_DIR.'explorerFunctions.php');
switch ($playlistFormat){
// M3U
case 'm3u':
$output="#EXTM3U\n\n";
foreach ($playlist as $v){
$output.='#EXTINF '.((isset($v['ai']['length']))?($v['ai']['length']/1000):'-1').','.
((isset($v['ai']['title']))?$v['ai']['title']:cfFileWithoutExtension(basename($v['cfn'])));
$output.="\n".fileLink($v,$encodingOptions,$addressMode,$preUTF8Encode)."\n";
}
break;
// Winamp PLS
case 'pls':
$output="[playlist]\nNumberOfEntries=".count($playlist)."\n\n";
$i=1;
foreach ($playlist as $v){
$output.='File'.$i.'='.fileLink($v,$encodingOptions,$addressMode,$preUTF8Encode)."\n";
$output.='Length'.$i.'='.((isset($v['ai']['length']))?($v['ai']['length']/1000):'-1')."\n";
$output.='Title'.$i.'='.((isset($v['ai']['title']))?$v['ai']['title']:cfFileWithoutExtension(basename($v['cfn'])))."\n\n";
$i++;
}
$output.="\nVersion=2";
break;
// MS WMP ASX
case 'asx':
$output="<ASX VERSION=\"3.0\">\n <PARAM NAME=\"encoding\" VALUE=\"utf-8\" />\n <TITLE>".cfCaption('explorerAudioPlaylist')."</TITLE>\n";
foreach ($playlist as $v){
$output.=" <ENTRY>\n";
$output.=' <TITLE>'.cfUTF8Encode((isset($v['ai']['title']))?$v['ai']['title']:cfFileWithoutExtension(basename($v['cfn'])))."</TITLE>\n";
$output.=' <REF HREF="'.fileLink($v,$encodingOptions,$addressMode,$preUTF8Encode).'" />';
if(isset($v['ai']['length'])) $output.="\n <DURATION VALUE=\"".(floor($v['ai']['length']/1000)).'" />';
$output.="\n </ENTRY>\n";
}
$output.="</ASX>";
break;
// Internal XML format, used by audio flash player
case 'xml':
$output='<?xml version="1.0" encoding="utf-8"?>'."\n".'<playlist volume="'.((cfUGetVar('audioVolume')!==false)?cfUGetVar('audioVolume'):'80').'">'."\n";
foreach ($playlist as $v){
$file=cfXMLEncodeProperty(fileLink($v,$encodingOptions,$addressMode,$preUTF8Encode));
$output.='<audio externalRef="'.$file.'" songLabel="'.((isset($v['ai']['label']))?cfXMLEncodeProperty(cfUTF8Encode($v['ai']['label'])):'').'" file="'.$file."\" />\n";
}
$output.='</playlist>';
break;
default:
throw new Exception('Unsupported output playlist format');
return;
}
return $output;
}
/**
* @desc Convert a PHP associative array to string definition of JS associative array
*
* @param array $inArray
* @return string
*/
function fiPHPArrayToJSArray($inArray){
$out='';
if(!is_array($inArray)) return '{}';
foreach($inArray as $k=>$v) {
// HTML code, do not protect
if($k=='vhtml') $k='v';
elseif($k=='chtml') $k='c';
elseif(!is_array($v) && substr($v,0,5)!='code:') $v=str_replace('<','<',$v);
// Key
$out.=",'".addcslashes($k,'"\'')."':";
// Array
if(is_array($v)) $out.=fiPHPArrayToJSArray($v);
// Else: protect string
else{
$l=strlen($v);
for ($i=0;$i<$l;$i++) if(ord(substr($v,$i,1))<32) $v[$i]=' ';
// Caption: don't utf-8 encode
if($k=='c') $out.="'".addcslashes($v,'"\'\\')."'";
// other value
else $out.="'".addcslashes(cfUTF8Encode($v,false,false),'"\'\\')."'";
}
}
return '{'.substr($out,1).'}';
}
/**
* @desc Create an array with processed exif data, false if no exif data
*
* @param string $completeFilename: jpg or tiff filename
* @return array
*/
function mExifArray($completeFilename){
$ext=cfFileExtension($completeFilename);
if($ext!='jpg' && $ext!='jpeg' && $ext!='tiff') return false;
if(!($raw=@exif_read_data($completeFilename))) return false;
// Discarded tags
$discarded=array('FileName','FileDateTime','FileSize','MimeType','SectionsFound','FileType','DateTime','InteroperabilityOffset');
// Transformed tags
$transformedTags=array(
'Flash'=>array(
'0' => 'No Flash',
'1' => 'Fired',
'5' => 'Fired, Return not detected',
'7' => 'Fired, Return detected',
'8' => 'On, Did not fire',
'9' => 'On',
'd' => 'On, Return not detected',
'f' => 'On, Return detected',
'10' => 'Off',
'14' => 'Off, Did not fire, Return not detected',
'18' => 'Auto, Did not fire',
'19' => 'Auto, Fired',
'1d' => 'Auto, Fired, Return not detected',
'1f' => 'Auto, Fired, Return detected',
'20' => 'No flash function',
'30' => 'Off, No flash function',
'41' => 'Fired, Red-eye reduction',
'45' => 'Fired, Red-eye reduction, Return not detected',
'47' => 'Fired, Red-eye reduction, Return detected',
'49' => 'On, Red-eye reduction',
'4d' => 'On, Red-eye reduction, Return not detected',
'4f' => 'On, Red-eye reduction, Return detected',
'50' => 'Off, Red-eye reduction',
'58' => 'Auto, Did not fire, Red-eye reduction',
'59' => 'Auto, Fired, Red-eye reduction',
'5d' => 'Auto, Fired, Red-eye reduction, Return not detected',
'5f' => 'Auto, Fired, Red-eye reduction, Return detected'),
'SceneType'=>array(
1 => 'Directly photographed'),
'FileSource'=>array(
1 => 'Film Scanner',
2 => 'Reflection Print Scanner',
3 => 'Digital Camera'),
'ExposureMode'=>array(
0 => 'Auto',
1 => 'Manual',
2 => 'Auto bracket'),
'SensingMethod'=>array(
1 => 'Monochrome area',
2 => 'One-chip color area',
3 => 'Two-chip color area',
4 => 'Three-chip color area',
5 => 'Color sequential area',
6 => 'Monochrome linear',
7 => 'Trilinear',
8 => 'Color sequential linear'),
'PhotometricInterpretation'=>array(
0 => 'WhiteIsZero',
1 => 'BlackIsZero',
2 => 'RGB',
3 => 'RGB Palette',
4 => 'Transparency Mask',
5 => 'CMYK',
6 => 'YCbCr',
8 => 'CIELab',
9 => 'ICCLab',
10 => 'ITULab',
32803 => 'Color Filter Array',
32844 => 'Pixar LogL',
32845 => 'Pixar LogLuv',
34892 => 'Linear Raw'),
'YCbCrPositioning'=>array(
1 => 'Centered',
2 => 'Co-sited'),
'ResolutionUnit'=>array(
1 => 'None',
2 => 'Inches',
3 => 'cm'),
'FocalPlaneResolutionUnit'=>array(
1 => 'None',
2 => 'Inches',
3 => 'cm'),
'CustomRendered'=>array(
0 => 'Normal',
1 => 'Custom'),
'Predictor'=>array(
1 => 'None',
2 => 'Horizontal differencing'),
'Sharpness'=>array(
0 => 'Normal',
1 => 'Soft',
2 => 'Hard'),
'Contrast'=>array(
0 => 'Normal',
1 => 'Soft',
2 => 'Hard'),
'Saturation'=>array(
0 => 'Normal',
1 => 'Low saturation',
2 => 'High saturation'),
'ColorSpace'=>array(
1 => 'sRGB',
2 => 'Adobe RGB',
65535 => 'Uncalibrated'),
'GainControl'=>array(
0 => 'None',
1 => 'Low gain up',
2 => 'High gain up',
3 => 'Low gain down',
4 => 'High gain down'),
'SceneCaptureType'=>array(
0 => 'Standard',
1 => 'Landscape',
2 => 'Portrait',
3 => 'Night scene'),
'WhiteBalance'=>array(
0 => 'Auto white balance',
1 => 'Manual white balance'),
'MeteringMode'=>array(
0 => 'unknown',
1 => 'Average',
2 => 'CenterWeightedAverage',
3 => 'Spot',
4 => 'MultiSpot',
5 => 'Pattern',
6 => 'Partial',
255 => 'other'),
'LightSource'=>array(
0 => 'unknown',
1 => 'Daylight',
2 => 'Fluorescent',
3 => 'Tungsten (incandescent light)',
4 => 'Flash',
9 => 'Fine weather',
10 => 'Cloudy weather',
11 => 'Shade',
12 => 'Daylight fluorescent (D 5700 û 7100K)',
13 => 'Day white fluorescent (N 4600 û 5400K)',
14 => 'Cool white fluorescent (W 3900 û 4500K)',
15 => 'White fluorescent (WW 3200 û 3700K)',
17 => 'Standard light A',
18 => 'Standard light B',
19 => 'Standard light C',
20 => 'D55',
21 => 'D65',
22 => 'D75',
23 => 'D50',
24 => 'ISO studio tungsten',
255 => 'Other light source'),
'ExposureProgram'=>array(
0 => 'Not defined',
1 => 'Manual',
2 => 'Normal program',
3 => 'Aperture priority',
4 => 'Shutter priority',
5 => 'Creative program (biased toward depth of field)',
6 => 'Action program (biased toward fast shutter speed)',
7 => 'Portrait mode (for closeup photos with the background out of focus)',
8 => 'Landscape mode (for landscape photos with the background in focus)'),
'Orientation'=>array(
1 => 'Horizontal (normal)',
2 => 'Mirror horizontal',
3 => 'Rotate 180',
4 => 'Mirror vertical',
5 => 'Mirror horizontal and rotate 270 CW',
6 => 'Rotate 90 CW',
7 => 'Mirror horizontal and rotate 90 CW',
8 => 'Rotate 270 CW')
);
$exif=array();
// Browse properties
foreach ($raw as $tag=>$value) if(!is_array($value)) {
$discard=false;
if(substr($tag,0,12)=='UndefinedTag') continue;
if($tag=='FileSource') $value=ord($value);
// Forbidden characters
for($i=0;$i<strlen($value);$i++){
if(($ord=ord(substr($value,$i,1)))<32 && $ord!=9 && $ord!=10 && $ord!=13){
$discard=true;
break;
}
}
if($discard) continue;
// Discarded tags
foreach ($discarded as $k=>$d)
if($tag==$d) {$discard=true;break;}
if($discard) continue;
// Set value
if($tag=='Flash') $value=dechex($value);
if($tag=='DateTimeOriginal' || $tag=='DateTimeDigitized') $value=date(cfCaption('_FULL_DATE_FORMAT'),strtotime($value));
if(isset($transformedTags[$tag][$value])) $exif[$tag]=$transformedTags[$tag][$value]; else $exif[$tag]=$value;
}
return $exif;
}
/**
* @desc Return true if filename has detailed information (EXIF data, ...)
*
* @param string $completeFilename
* @return boolean
*/
function fiHasInfo($completeFilename){
$mimeType=efFileType($completeFilename);
if($mimeType=='image') return true;
//$ext=cfFileExtension($completeFilename);
return false;
}
/**
* @desc Return flash swf specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoFolder($completeFilename,$getThumbnail){
$info=array();
// Total contained files size
$totalSize=0;
$nbFiles=0;
$nbFolders=0;
$firstFiles=array();
$firstFolders=array();
$nbFirst=10;
// Browse subfolders and files for total size and first elements
foreach (glob($completeFilename.'/*') as $cfn) {
if(is_file($cfn)) {
$totalSize+=cfFileSize($cfn);
$nbFiles++;
if(count($firstFiles)<$nbFirst) $firstFiles[]=basename($cfn);
}
else {
$nbFolders++;
if(count($firstFolders)<$nbFirst) $firstFolders[]=basename($cfn);
}
}
$info['fileSize']=array('c'=>cfCaption('genSize'),'v'=>efFileSizeFormat($totalSize));
// Icon
$info['icon']=outIcon('/fi/folder');
// Extra data
$info['extra']['extraTitle']=array('c'=>cfCaption('explorerTotalFiles',$nbFolders,$nbFiles));
if(count($firstFiles) && count($firstFolders)) $info['extra'][0]=array('chtml'=>'<b style="padding-left:15em"> </b>','vhtml'=>'<b style="padding-left:15em"> </b>');
else $info['extra'][0]=array('c'=>' ','v'=>' ');
// First files and folders
for($i=0;$i<$nbFirst;$i++){
if(!isset($firstFiles[$i]) && !isset($firstFolders[$i])) break;
// Folders
if(!isset($firstFolders[$i])) $fo='';
elseif ($i==$nbFirst-1) $fo='...';
else $fo=outImage(outIcon('fi/folder'),false,false,'margin-right:0.3em',0.7).cfStrTruncate(cfUTF8Encode($firstFolders[$i]),40);
// Files
if(!isset($firstFiles[$i])) $fi=' ';
elseif ($i==$nbFirst-1) $fi='...';
else $fi=outImage(efIcon($firstFiles[$i]),false,false,'margin-right:0.3em',0.7).cfStrTruncate($firstFiles[$i],50);
$info['extra'][$i+1]=array('chtml'=>$fo,'vhtml'=>$fi);
}
return $info;
}
/**
* @desc Return image-specific info
*
* @param string $completeFilename: image filename
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoImage($completeFilename,$getThumbnail){
$info=array();
$ext=cfFileExtension($completeFilename);
// Image dimensions
if($ext=='itc' || $ext=='itc2'){
if(($sourceImage=@imagecreatefromstring(substr(file_get_contents($completeFilename),(($ext=='itc')?500:492))))){
$width=imagesx($sourceImage);
$height=imagesy($sourceImage);
unset($sourceImage);
}
}
if(!isset($width)) list($width, $height, $type, $attr) = @getimagesize($completeFilename);
if($width) $info['extra']['imageSize'] = array('c'=>cfCaption('genSize'), 'v'=>$width.'x'.$height.' '.cfCaption('genPixels'));
else $info['extra']['imageSize'] = array('c'=>cfCaption('genSize'), 'v'=>'? x ? '.cfCaption('genPixels'));
// Thumbnail URL and size
if($getThumbnail && cfRGetVar('path') && $width) {
$info['thumbnailURL']=cfExtImage($completeFilename,$_ENV['thumbnailMaxWidth'],$_ENV['thumbnailMaxHeight']);
if($width && $height){
if($width/$height>$_ENV['thumbnailMaxWidth']/$_ENV['thumbnailMaxHeight'])
{$info['thumbnailURLW']=$_ENV['thumbnailMaxWidth'];$info['thumbnailURLH']=$_ENV['thumbnailMaxWidth']*$height/$width;}
else
{$info['thumbnailURLH']=$_ENV['thumbnailMaxHeight'];$info['thumbnailURLW']=$_ENV['thumbnailMaxHeight']*$width/$height;}
}
else{
$info['thumbnailURLW']=$_ENV['thumbnailMaxWidth'];
$info['thumbnailURLH']=$_ENV['thumbnailMaxHeight'];
}
}
// Exif data
if($ext=='jpg' || $ext=='jpeg' || $ext=='tiff') {
if($exif=mExifArray($completeFilename)) $info['extra']+=$exif;
}
return $info;
}
/**
* @desc Return audio-file specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoAudio($completeFilename,$getThumbnail=false){
$info=array();
$ext=cfFileExtension($completeFilename);
// Playlists
if($ext=='m3u' || $ext=='pls'){
$nb=0;
$info['extra']['extraTitle']=array('c'=>cfCaption('explorerAudioPlaylist').cfCaption('genSeparator'));
$fp=@fopen($completeFilename,'r');
while (!feof($fp)) {
if($line=trim(fgets($fp,1024))){
// M3U playlist
if($ext=='m3u' && substr($line,0,1)!='#'){
$info['extra'][++$nb]=array('c'=>($nb).') ','v'=>basename($line));
}
// Winamp PLS playlist
elseif($ext=='pls' && substr($line,0,4)=='File' && strpos($line,'=')){
$line=substr($line,strpos($line,'=')+1);
$info['extra'][++$nb]=array('c'=>($nb).') ','v'=>basename($line));
}
}
}
@fclose($fp);
// Thumbnail
if($getThumbnail){
$info['thumbnailURL']='/gfx/fi/big/icoM3U.png';
$info['thumbnailURLW']=94;
$info['thumbnailURLH']=120;
$info['thumbnailNoFrame']=1;
}
}
// Audio files
else{
$audio=efGetAudioInfo($completeFilename,true);
foreach ($audio as $key=>$value) if(!strlen($value)) unset($audio[$key]);
$info['extra']['extraTitle']=array('c'=>cfCaption('explorerAudioFileInfo').cfCaption('genSeparator'));
if(isset($audio['artist'])) $info['extra']['artist']=array('c'=>cfCaption('explorerAudioArtist'),'v'=>$audio['artist']);
if(isset($audio['album'])) $info['extra']['album']=array('c'=>cfCaption('explorerAudioAlbum'),'v'=>$audio['album']);
if(isset($audio['track'])) $info['extra']['track']=array('c'=>cfCaption('explorerAudioTrack'),'v'=>$audio['track']);
if(isset($audio['title'])) $info['extra']['title']=array('c'=>cfCaption('explorerAudioTitle'),'v'=>$audio['title']);
if(isset($audio['genre'])) $info['extra']['genre']=array('c'=>cfCaption('explorerAudioGenre'),'v'=>$audio['genre']);
if(isset($audio['year'])) $info['extra']['year']=array('c'=>cfCaption('explorerAudioYear'),'v'=>$audio['year']);
if(isset($audio['comment'])) $info['extra']['comment']=array('c'=>cfCaption('genComments'),'v'=>$audio['comment']);
// Thumbnail
if($getThumbnail){
if(!isset($audio['APIC'])){
require_once(INCLUDE_DIR.'explorerFunctions.php');
efGetCoverFromFolder($completeFilename,$score);
}
if(isset($audio['APIC'])||$score>=4){
$info['thumbnailURL']=cfExtImage($completeFilename,min($_ENV['thumbnailMaxWidth'],$_ENV['thumbnailMaxHeight']),min($_ENV['thumbnailMaxWidth'],$_ENV['thumbnailMaxHeight']));
$info['thumbnailURLW']=min($_ENV['thumbnailMaxWidth'],$_ENV['thumbnailMaxHeight']);
$info['thumbnailURLH']=min($_ENV['thumbnailMaxWidth'],$_ENV['thumbnailMaxHeight']);
}
else{
$info['thumbnailURL']='/gfx/fi/big/icoMus.png';
$info['thumbnailURLW']=94;
$info['thumbnailURLH']=120;
$info['thumbnailNoFrame']=1;
}
}
}
return $info;
}
/**
* @desc Return text file specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoVideo($completeFilename,$getThumbnail){
require_once(INCLUDE_DIR.'viewVideoFunctions.php');
$info=array();
$ext=cfFileExtension($completeFilename);
$length=512;
// Video dimensions
list($width,$height)=vvfVideoDimensions($completeFilename,false);
if($width) $info['extra']['videoSize'] = array('c'=>cfCaption('genSize'), 'v'=>$width.'x'.$height.' '.cfCaption('genPixels'));
// Video duration
$duration=vvfVideoDuration($completeFilename);
$h=floor($duration/3600);
$m=floor(($duration-3600*$h)/60);
$s=$duration%60;
$info['extra']['duration']=array('c'=>cfCaption('explorerAudioTime'),'v'=>str_replace('%3',$s,cfCaption('calHourMinSec',$h,$m)));
// Bitrate
if($duration>0){
setlocale(LC_NUMERIC,cfCaption('_ISO_639'));
$loc=localeconv();
if(ord($loc['thousands_sep'])==160) $loc['thousands_sep']=' ';
setlocale(LC_NUMERIC,'eng');
$info['extra']['br']=array('c'=>cfCaption('genBitrate'),
number_format(floor(8*cfFileSize($completeFilename)/(1000*$duration)),0,$loc['decimal_point'],$loc['thousands_sep']).
' '.cfCaption('explorerKBitPS'));
}
// Thumbnail
// Thumbnail URL and size
if($getThumbnail && cfRGetVar('path') && $width) {
// Reduce thumbnail size
if(cfBGetVar('flash')) $_ENV['thumbnailMaxWidth']=120;
// Compute thumbnail width & height
if($width/$height>$_ENV['thumbnailMaxWidth']/$_ENV['thumbnailMaxHeight'])
{$info['thumbnailURLW']=$_ENV['thumbnailMaxWidth'];$info['thumbnailURLH']=$_ENV['thumbnailMaxWidth']*$height/$width;}
else
{$info['thumbnailURLH']=$_ENV['thumbnailMaxHeight'];$info['thumbnailURLW']=$_ENV['thumbnailMaxHeight']*$width/$height;}
$info['thumbnailURLW']=floor($info['thumbnailURLW']);
$info['thumbnailURLH']=floor($info['thumbnailURLH']);
// If browser doesn't support flash, display static screenshot
if(!cfBGetVar('flash'))
$info['thumbnailURL']=cfExtVideo($completeFilename,array('image'=>'1','w'=>$info['thumbnailURLW'],'h'=>$info['thumbnailURLH']));
// Else, generate control-less flash player
else{
require_once(INCLUDE_DIR.'viewVideoFunctions.php');
// Player code
$offset=max(0,min($duration-10,5));
$offset=0;
// Video URL
$src=cfExtVideo($completeFilename,array('w'=>$info['thumbnailURLW'],'h'=>$info['thumbnailURLH'],'q'=>'medium','noSound'=>1,'flv'=>1,'offset'=>$offset),'relative','b64');
$info['thumbnailURL']='code:';
$info['thumbnailURL'].='<object id="playerVideo" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http'.((isset($_SERVER['HTTPS']))?'s':'').'://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'.$info['thumbnailURLW'].'" height="'.$info['thumbnailURLH'].'" align="middle">';
$info['thumbnailURL'].='<param name="allowScriptAccess" value="sameDomain" />';
$info['thumbnailURL'].='<param name="allowFullScreen" value="true" />';
$info['thumbnailURL'].='<param name="fullScreenRect" value="true" />';
$info['thumbnailURL'].='<param name="movie" value="'.cfHostName().'/js/vplayer.swf?file='.$src.'&w='.$info['thumbnailURLW'].'&h='.$info['thumbnailURLH'].'&offset='.$offset.'&autoplay=1&buffer=0&browser='.cfGetBrowser().'&noControls=1&loop=1&background=white&bs=5" />';
$info['thumbnailURL'].='<param name="quality" value="high" />';
$info['thumbnailURL'].='<param name="bgcolor" value="#000000" />';
$info['thumbnailURL'].='<embed name="playerVideo" id="playerVideoEmbed" src="'.cfHostName().'/js/vplayer.swf?file='.$src.'&w='.$info['thumbnailURLW'].'&h='.$info['thumbnailURLH'].'&offset='.$offset.'&autoplay=1&buffer=0&browser='.cfGetBrowser().'&noControls=1&loop=1&background=white&bs=5"';
$info['thumbnailURL'].='swLiveConnect="true"';
$info['thumbnailURL'].='quality="high"';
$info['thumbnailURL'].='width="'.$info['thumbnailURLW'].'"';
$info['thumbnailURL'].='height="'.$info['thumbnailURLH'].'"';
$info['thumbnailURL'].='allowFullScreen="true"';
$info['thumbnailURL'].='fullScreenRect="true"';
$info['thumbnailURL'].='align="middle"';
$info['thumbnailURL'].='allowScriptAccess="sameDomain"';
$info['thumbnailURL'].='type="application/x-shockwave-flash"';
$info['thumbnailURL'].='pluginspage="'.'http'.((isset($_SERVER['HTTPS']))?'s':'').'://www.macromedia.com/go/getflashplayer"';
$info['thumbnailURL'].='/></object>';
}
}
return $info;
}
/**
* @desc Return text file specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoText($completeFilename,$getThumbnail){
$info=array();
$ext=cfFileExtension($completeFilename);
$length=512;
// IE URLs
if($ext=='url'){
$c=file_get_contents($completeFilename);
if(stripos($c,'url=')) {
$c=substr($c,stripos($c,'url=')+4);
if(strpos($c,"\n")) $c=trim(substr($c,0,strpos($c,"\n")));
$info['extra'][0]=array('c'=>'URL','vhtml'=>'<a href="#" style="text-decoration:underline">'.$c.'</a>');
}
}
// Thumbnail
if($getThumbnail){
$content='';
$highlighted=array("c"=>"CPP","cpp"=>"CPP","css"=>"CSS","dtd"=>"DTD","java"=>"JAVA","js"=>"JAVASCRIPT","sql"=>"SQL","mysql"=>"MYSQL","perl"=>"PERL","php"=>"PHP","py"=>"PYTHON","ruby"=>"RUBY","xml"=>"XML","html"=>"XML","htm"=>"XML","opml"=>"XML","vbs"=>"VBSCRIPT","bas"=>"VBSCRIPT","ctl"=>"VBSCRIPT","cls"=>"VBSCRIPT","frm"=>"VBSCRIPT");
// See if content can be coloured
if(isset($highlighted[$ext])) {
require_once(INCLUDE_DIR.'Text/Highlighter.php');
// Get head of text file
$content='';
if($fp=@fopen($completeFilename,'r')){
$lines=0;
while (!feof($fp) && strlen($content)<$length && ++$lines<15)
$content.=fgets($fp,$length);
$all = feof($fp);
@fclose($fp);
$hl = Text_Highlighter::factory($highlighted[cfFileExtension($completeFilename)]);
$content=$hl->highlight($content);
$content=str_replace("\r","<br>",str_replace("\n","<br>",str_replace("\r\n","<br>",$content)));
if(!$all) $content.='<br>...<br>';
}
}
// Display as plain text
else {
// Get head of text file
$content='';
if($fp=@fopen($completeFilename,'r')){
$lines=0;
while (!feof($fp) && strlen($content)<$length && ++$lines<15)
$content.='<br>'.str_replace('<','<',trim(fgets($fp,$length)));
if(!feof($fp)) $content.='<br>...<br>';
@fclose($fp);
}
$content=str_replace(' ',' ',str_replace(' ',' ',$content));
$content='<div class="hl-main">'.substr($content,4).'</div>';
}
$info['thumbnailURL']='code:'.$content;
/*
$info['extra']['extraTitle']=array('c'=>cfCaption('genContent').cfCaption('genSeparator'));
$info['extra']['content']=array('c'=>'','vhtml'=>$content);
*/
}
return $info;
}
/**
* @desc Return archives specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoArchive($completeFilename,$getThumbnail){
$info=array();
$ext=cfFileExtension($completeFilename);
$length=512;
$zip = new ZipArchive();
if(!@$zip->open($completeFilename)) return $info;
// Thumbnail
if($getThumbnail && $zip->numFiles>0){
$content='<b>'.cfCaption('genFiles').'</b><br>';
for($i=0;$i<min($zip->numFiles,10);$i++){
$content.=($zip->getNameIndex($i)).'<br>';
}
if($zip->numFiles>10) $content.='...<br>';
$info['thumbnailURL']='code:'.$content;
}
// ZIP comments
if($zip->getArchiveComment()){
$info['extra']['extraTitle']=array('c'=>cfCaption('genComments').cfCaption('genSeparator'));
$info['extra']['content']=array('c'=>'','v'=>$zip->getArchiveComment());
}
$zip->close();
return $info;
}
/**
* @desc Return flash swf specific info
*
* @param string $completeFilename: filename including path
* @param boolean $getThumbnail: true to include thumbnail
* @return array
*/
function fiGetInfoFlash($completeFilename,$getThumbnail){
$info=array();
$ext=cfFileExtension($completeFilename);
$length=512;
// Thumbnail
if($getThumbnail){
$info['thumbnailURL']='code:<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http'.((isset($_SERVER['HTTPS']))?'s':'').'://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'.$_ENV['thumbnailMaxWidth'].'" height="'.$_ENV['thumbnailMaxHeight'].'">';
$info['thumbnailURL'].='<param name="movie" value="'.cfExtDownload($completeFilename).'" />';
$info['thumbnailURL'].='<param name="wmode" value="transparent" />';
$info['thumbnailURL'].='<embed src="'.cfExtDownload($completeFilename).'" width="'.$_ENV['thumbnailMaxWidth'].'" height="'.$_ENV['thumbnailMaxHeight'].'" type="application/x-shockwave-flash" pluginspage="http'.((isset($_SERVER['HTTPS']))?'s':'').'://www.macromedia.com/go/getflashplayer" wmode="transparent" /></object>';
}
return $info;
}
/**
* @desc Return an array containing file detailled information
*
* @param string $completeFilename
* @return array: (property name => property value)
*/
function fiGetInfo($completeFilename, $getThumbnail=true, $getExtraData=true){
wSession_write_close();
if(!file_exists($completeFilename)) return false;
$ext=cfFileExtension($completeFilename);
// Files with not-text mime type but that should anyway be viewed as text files
$otherTextExt=array('js'=>1,'bat'=>1);
require_once(INCLUDE_DIR.'explorerFunctions.php');
/**
* Common data
*/
// File name
$info['filename']=basename($completeFilename);
// File size
if(is_file($completeFilename)) $info['fileSize']=array('c'=>cfCaption('genSize'),'v'=>efFileSizeFormat(cfFileSize($completeFilename)));
// File creation date
$info['cTime']=array('c'=>cfCaption('dateCTime'),'v'=>date(cfCaption('_FULL_DATE_FORMAT',@filectime($completeFilename))));
// File modification date
$info['mTime']=array('c'=>cfCaption('dateMTime'),'v'=>date(cfCaption('_FULL_DATE_FORMAT',@filemtime($completeFilename))));
// Icon
if(is_file($completeFilename)) $info['icon']=efIcon($completeFilename,true);
else $info['icon']=outIcon('/fi/folder');
// text separator
$info['sep']=cfCaption('genSeparator');
// Folder specific data
if(is_dir($completeFilename)) $info+=fiGetInfoFolder($completeFilename,$getThumbnail);
// Image specific data
elseif(efFileType($completeFilename)=='image') $info+=fiGetInfoImage($completeFilename,$getThumbnail);
// Audio file specific data
elseif(efFileType($completeFilename)=='audio') $info+=fiGetInfoAudio($completeFilename,$getThumbnail);
// Video file specific data
elseif(efFileType($completeFilename)=='video') $info+=fiGetInfoVideo($completeFilename,$getThumbnail);
// Text file specific data
elseif(efFileType($completeFilename)=='text' || !$ext || isset($otherTextExt[$ext])) $info+=fiGetInfoText($completeFilename,$getThumbnail);
// Flash file
elseif (cfFileExtension($completeFilename)=='swf') $info+=fiGetInfoFlash($completeFilename,$getThumbnail);
// Zip file
elseif (cfFileExtension($completeFilename)=='zip') $info+=fiGetInfoArchive($completeFilename,$getThumbnail);
// Other file formats : try to get thumbnail
elseif ($getThumbnail && !cfGGetVar('disableCreateJPG')){
$res=cfStreamProc('"'.cfAppBinDir().'/createJPG.exe" "'.$completeFilename.'" check 160 160',array('stdout'=>'return'),array('haltOnSeq'=>chr(12)));
if(substr($res,-1)==chr(12)) $res=substr($res,0,strlen($res)-1);
if($res!='NOK'){
@list($ok,$w,$h)=explode(':',$res);
$info['thumbnailURL']=cfExtImage($completeFilename,$w,$h);
$info['thumbnailURLW']=$w;
$info['thumbnailURLH']=$h;
$info['extra']=array('default'=>array('c'=>'','v'=>' '));
}
}
// No extra data...
if((!isset($info['extra']) || !count($info['extra'])) && !isset($info['thumbnailURL'])) $info['extra']=array('default'=>array('c'=>cfCaption('genNoPreview'),'v'=>' '));
if(!$getExtraData) unset($info['extra']);
return $info;
}